<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
model('jy_weishop/member')->checklogin();
if($_RQ['op']=='main'){
	if($_RQ['merchid']){
		$merchid = intval($_RQ['merchid']);
		$this->session('merchid',$merchid);
	}else{
		$merchid=$this->session('merchid');
	}
	if($merchid){
		$merch = pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
		$merch['pcd']=json_decode($merch['pcd'],true);
		$merch['lat_lng']=json_decode($merch['lat_lng'],true);
	}
	$tableid=$this->session('tableid');
	$item=array('from'=>$_RQ['from'],'merchid'=>$merchid,'tableid'=>$tableid);
	$return['item']=$item;
	$return['merch']=$merch;
	$return['nums']=array(1,2,3,4,5,6,7,8,9,10);
	$return['childnums']=array(0,1,2,3,4,5);
	set_html('title','扫码点餐');
	exi($return);
}
if($_RQ['op']=='get'){
	$post=get_postdata();
	$id=$post['id'];
	if(!$post['num']){
		exi('请选择用餐人数！','error');
	}
	if($post['merchid']){
		$merchid = intval($post['merchid']);
		$this->session('merchid',$merchid);
	}
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$number = pdo_getcolumn('jy_weishop_queue_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'merchid'=>$post['merchid'],'status'=>0,'createtime >'=>$daytime),'number');
	if($number){
		exi('您已经取号了！您的排号：'.$number,'error','jy_merch/merch/');
	}
	model('jy_weishop/queue')->create($post);
	if($post['nogoback']){
		exi('成功排号！');
	}else{
		exi('成功排号！','','jy_merch/merch/');
	}
}	
?>